#include "xxManager.h"

xxManager::xxManager(QObject* parent)
	:QObject(parent), m_mutex(QMutex::Recursive)
{
	init();
}

xxManager::~xxManager()
{
}

xxManager& xxManager::globalInstance()
{
	static xxManager instance;
	return instance;
}

void xxManager::init()
{
    static bool s_inited = false;
    if (s_inited == true)
        return;
    m_worker.moveToThread(&m_thread);

    connect(&m_thread, &QThread::started, &m_worker, &xxWorker::init);

    m_thread.start();
}

void xxManager::shutdown()
{
    if (m_thread.isRunning()) {
        QMetaObject::invokeMethod(&m_worker, "uninit", Qt::BlockingQueuedConnection);
        m_thread.quit();
        m_thread.wait();
    }
}
